package com.ruoyi.system.outto.goods.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.exception.GlobalException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.system.V2.gameAttr.mapper.GameAttributeMapper;
import com.ruoyi.system.V2.goodInfo.mapper.GoodsInfoImgMapper;
import com.ruoyi.system.V2.inter.mapper.ArtRecMapper;
import com.ruoyi.system.model.domain.*;
import com.ruoyi.system.model.dto.GoodsInfoAndAttrValueDto;
import com.ruoyi.system.model.mapper.InfoImgMapper;
import com.ruoyi.system.outto.core.LCConstant;
import com.ruoyi.system.outto.core.MapUntils;
import com.ruoyi.system.outto.dto.HttpUtil;
import com.ruoyi.system.outto.game.CommonApi;
import com.ruoyi.system.outto.game.TXYAPI;
import com.ruoyi.system.outto.goods.NEWTXYAPI;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author lz
 * @version 1.0
 * @date 2022/6/5 16:19
 */
@Slf4j
@Service
public class NEWTXYAPIImpl implements NEWTXYAPI {

    @Resource
    private InfoImgMapper infoImgMapper;
    @Value("${desc.title}")
    private String descTitle;
    @Autowired
    private CommonApi commonApi;
    @Resource
    private GoodsInfoImgMapper goodsInfoImgMapper;
    @Resource
    private GameAttributeMapper gameAttributeMapper;
    @Resource
    private ArtRecMapper artRecMapper;

    @Override
    public AjaxResult addGame(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner salePartner) {
        String path = "/api3/shop/add/";
        Map<String, Object> result = new HashMap<>();
        Map<String, Object> params = params(goodsInfoAndAttrValueDto,salePartner);
        log.info("天下游添加接口请求参数={}", JSONObject.toJSONString(params));
        String response = HttpUtils.doPostForm(salePartner.getOther() + path, params, null);
        log.info("天下游添加接口返回参数={}", response);
        JSONObject resultJson = JSONObject.parseObject(response);
        if (!"true".equals(resultJson.getString("result"))) {
            result.put("code", 500);
        } else {
            result.put("code", 200);
            ArtRec artRecreq = new ArtRec();
            artRecreq.setConfig(salePartner.getId());
            artRecreq.setAccountId(goodsInfoAndAttrValueDto.getId());
            List<ArtRec> artRecs = artRecMapper.selectArtRecList(artRecreq);
            if(artRecs.size()>0) {
                artRecs.get(0).setOutid(String.valueOf(goodsInfoAndAttrValueDto.getId()));
                artRecMapper.updateArtRec(artRecs.get(0));
            }else{
                artRecreq.setAccountId(goodsInfoAndAttrValueDto.getId());
                artRecreq.setCreateId(goodsInfoAndAttrValueDto.getCreateId());
                artRecreq.setType(LCConstant.interAdd);
                artRecreq.setConfig(salePartner.getId());
                artRecreq.setSaleCode(salePartner.getSaleName());
                artRecreq.setOutid(String.valueOf(goodsInfoAndAttrValueDto.getId()));
                artRecMapper.insertArtRec(artRecreq);
            }
        }

        result.put("req", JSONObject.toJSONString(params));
        result.put("res", response);
        result.put("msg", resultJson.getString("message"));
        return AjaxResult.success(result);
    }

    @Override
    public AjaxResult editGame(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner salePartner) {
        String path = "/api3/shop/edit/price/";
        Map<String, Object> result = new HashMap<>();
        Map<String, String> params = new TreeMap<>();
        params.put("token", salePartner.getSaleKey());
        params.put("shopid", String.valueOf(goodsInfoAndAttrValueDto.getId()));
        params.put("price", String.valueOf(goodsInfoAndAttrValueDto.getPrice()));
        log.info("天下游编辑改价接口请求参数={}", JSONObject.toJSONString(params));
        String response = HttpUtil.doGet(salePartner.getOther() + path, params, null);
        log.info("天下游编辑改价接口返回参数={}", response);
        JSONObject resultJson = JSONObject.parseObject(response);
        if (!"true".equals(resultJson.getString("result"))) {
            result.put("code", 500);
        } else {
            result.put("code", 200);
        }

        result.put("req", JSONObject.toJSONString(params));
        result.put("res", response);
        result.put("msg", resultJson.getString("message"));
        return AjaxResult.success(result);
    }


    private Map<String, Object> params(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner salePartner) {
        GameAttribute gameAttribute = null;
        if(goodsInfoAndAttrValueDto.getGameName().contains("王者荣耀")){
            gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF16()));
        }else if(goodsInfoAndAttrValueDto.getGameName().contains("和平精英")){
            gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF10()));
        }else if(goodsInfoAndAttrValueDto.getGameName().contains("原神")){
            gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF20()));
        }else if(goodsInfoAndAttrValueDto.getGameName().contains("穿越火线")){
            gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF3()));
        }else if(goodsInfoAndAttrValueDto.getGameName().contains("光遇")){//=================================未配置游戏属性
            gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF20()));
        }else if(goodsInfoAndAttrValueDto.getGameName().contains("英雄联盟")){
            gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF1()));
        }else if(goodsInfoAndAttrValueDto.getGameName().contains("火影忍者")){//=================================未配置游戏属性
            gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF20()));
        }else if(goodsInfoAndAttrValueDto.getGameName().contains("枪战王者")){
            gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF10()));
        }else{
            throw new GlobalException("当前游戏暂不支持");
        }
        if(!Arrays.asList("王者荣耀","和平精英").contains(goodsInfoAndAttrValueDto.getGameName())){
            throw new GlobalException("游戏阁接口不支持此游戏：" + goodsInfoAndAttrValueDto.getGameName());
        }
        Map<String,Object> params = new HashMap<>();
        params.put("token", salePartner.getSaleKey());
        params.put("ownerid", salePartner.getTwoOther());
        params.put("shopid", goodsInfoAndAttrValueDto.getId());
        if (Objects.equals("王者荣耀",goodsInfoAndAttrValueDto.getGameName())){
            params.put("gameid", 1);
            if (Objects.equals("安卓QQ",goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName())){
                params.put("gamearea", 92);
            }
            if (Objects.equals("安卓微信",goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName())){
                params.put("gamearea", 93);
            }
            if (Objects.equals("苹果QQ",goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName())){
                params.put("gamearea", 94);
            }
            if (Objects.equals("苹果微信",goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName())){
                params.put("gamearea", 95);
            }
            params.put("yingdiid", goodsInfoAndAttrValueDto.getF17()==null||goodsInfoAndAttrValueDto.getF17().equals("")?"123456":goodsInfoAndAttrValueDto.getF17());
            params.put("shuliang", goodsInfoAndAttrValueDto.getF8()==null||goodsInfoAndAttrValueDto.getF8().equals("")?"0":goodsInfoAndAttrValueDto.getF8());
        }
        if (Objects.equals("和平精英",goodsInfoAndAttrValueDto.getGameName())){
            params.put("gameid", 24);
            if (Objects.equals("安卓QQ",goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName())){
                params.put("gamearea", 92);
            }
            if (Objects.equals("安卓微信",goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName())){
                params.put("gamearea", 93);
            }
            if (Objects.equals("苹果QQ",goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName())){
                params.put("gamearea", 94);
            }
            if (Objects.equals("苹果微信",goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName())){
                params.put("gamearea", 95);
            }
            params.put("yingdiid", goodsInfoAndAttrValueDto.getF13()==null||goodsInfoAndAttrValueDto.getF13().equals("")?"123456":goodsInfoAndAttrValueDto.getF13());
            params.put("shuliang", goodsInfoAndAttrValueDto.getF9()==null||goodsInfoAndAttrValueDto.getF9().equals("")?"0":goodsInfoAndAttrValueDto.getF9());
        }
        if (Objects.equals("穿越火线",goodsInfoAndAttrValueDto.getGameName())){
            params.put("gameid", 25);
            if (Objects.equals("南部战区",goodsInfoAndAttrValueDto.getGroupName())){
                params.put("gamearea", 97);
            }
            if (Objects.equals("东部战区",goodsInfoAndAttrValueDto.getGroupName())){
                params.put("gamearea", 98);
            }
            if (Objects.equals("北部战区",goodsInfoAndAttrValueDto.getGroupName())){
                params.put("gamearea", 99);
            }
            if (Objects.equals("西部战区",goodsInfoAndAttrValueDto.getGroupName())){
                params.put("gamearea", 100);
            }
            params.put("shuliang", goodsInfoAndAttrValueDto.getF8()==null||goodsInfoAndAttrValueDto.getF8().equals("")?"0":goodsInfoAndAttrValueDto.getF8());
        }
        if (Objects.equals("枪战王者",goodsInfoAndAttrValueDto.getGameName())){
            params.put("gameid", 26);
            if (Objects.equals("安卓QQ",goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName())){
                params.put("gamearea", 92);
            }
            if (Objects.equals("安卓微信",goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName())){
                params.put("gamearea", 93);
            }
            if (Objects.equals("苹果QQ",goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName())){
                params.put("gamearea", 94);
            }
            if (Objects.equals("苹果微信",goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName())){
                params.put("gamearea", 95);
            }
            params.put("shuliang", goodsInfoAndAttrValueDto.getF6()==null||goodsInfoAndAttrValueDto.getF6().equals("")?"0":goodsInfoAndAttrValueDto.getF6());
        }
        if (Objects.equals("英雄联盟",goodsInfoAndAttrValueDto.getGameName())){
            params.put("gameid", 28);
            JSONArray lolr = getLOLR();
            for (Object o : lolr) {
                String string = JSON.toJSONString(o);
                JSONObject jsonObject = JSON.parseObject(string);
                String sortName = jsonObject.getString("SortName");
                String ID = jsonObject.getString("ID");
                if (Objects.equals(sortName,goodsInfoAndAttrValueDto.getServerName())){
                    params.put("gamearea", ID);
                }
            }
            params.put("shuliang", goodsInfoAndAttrValueDto.getF4()==null||goodsInfoAndAttrValueDto.getF4().equals("")?"0":goodsInfoAndAttrValueDto.getF4());
        }
        if (Objects.equals("原神",goodsInfoAndAttrValueDto.getGameName())){
            params.put("gameid", 143);
            params.put("gamearea", 79);
            params.put("shuliang", goodsInfoAndAttrValueDto.getF8()==null||goodsInfoAndAttrValueDto.getF8().equals("")?"0":goodsInfoAndAttrValueDto.getF8());
        }
        if (Objects.equals("火影忍者",goodsInfoAndAttrValueDto.getGameName())){
            params.put("gameid", 47);
            if (Objects.equals("安卓QQ",goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName())){
                params.put("gamearea", 92);
            }
            if (Objects.equals("安卓微信",goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName())){
                params.put("gamearea", 93);
            }
            if (Objects.equals("苹果QQ",goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName())){
                params.put("gamearea", 94);
            }
            if (Objects.equals("苹果微信",goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName())){
                params.put("gamearea", 95);
            }
            params.put("shuliang", goodsInfoAndAttrValueDto.getF1()==null||goodsInfoAndAttrValueDto.getF1().equals("")?"0":goodsInfoAndAttrValueDto.getF1());
        }
        if (Objects.equals("光遇",goodsInfoAndAttrValueDto.getGameName())){
            throw new GlobalException("光遇游戏暂未开发");
        }

        params.put("shoptitle",goodsInfoAndAttrValueDto.getDes());
        BigDecimal bigDecimal = commonApi.addPrice(goodsInfoAndAttrValueDto.getPrice(), salePartner.getSeleep());
        params.put("shopprice",bigDecimal);

        GoodsInfoImg goodsInfoImg = new GoodsInfoImg();
        goodsInfoImg.setGoodsId(goodsInfoAndAttrValueDto.getId());
        goodsInfoImg.setType(Constants.STR_1);
        List<GoodsInfoImg> infoImgs = goodsInfoImgMapper.selectGoodsInfoImgList(goodsInfoImg);
        String imgs = "";
        if (!CollectionUtils.isEmpty(infoImgs)) {
            imgs = infoImgs.stream().map(i -> i.getImgUrl()).collect(Collectors.joining(","));
        } else {
            imgs = LCConstant.defaultImg;
        }
        params.put("shoppicurls", imgs);
        params.put("fangchenmi", "0");

        if("王者荣耀,和平精英".contains(goodsInfoAndAttrValueDto.getGameName())){
            if(gameAttribute.getFieldName().contains("可二次实名")){
                params.put("shiming", 0);
            }else{
                params.put("shiming", 1);
            }
            if(gameAttribute.getFieldName().contains("包人脸")){
                params.put("bface", 1);
            }else{
                params.put("bface", 0);
            }
        }else{
            if(gameAttribute.getFieldName().contains("有修改人脸机会/实名是本人")){
                params.put("shiming", 0);
            }else {
                params.put("shiming", 1);
            }
            if(gameAttribute.getFieldName().contains("无修改人脸机会/实名是本人")){
                params.put("bface", 1);
            }else{
                params.put("bface", 0);
            }
        }
//        if (Objects.equals(LCConstant.haveTwo, gameAttribute.getFieldName())) {
//            params.put("shiming", 0);
//        } else if (Objects.equals(LCConstant.bakFace, gameAttribute.getFieldName())) {
//            params.put("bface", 1);
//        }

//        if ("和平精英".equals(goodsInfoAndAttrValueDto.getGameName())){
//            params.put("shuliang", goodsInfoAndAttrValueDto.getF9()==null);
//        }else {
//            params.put("shuliang", accountInfo.getSkins());
//        }
        params.put("pdtext3", "111");
        return params;
    }


    @Override
    public AjaxResult delGame(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner salePartner) {
        String path = "/api3/shop/remove";
        Map<String, String> params = new HashMap<>();
        params.put("token", salePartner.getSaleKey());
        params.put("shopid", String.valueOf(goodsInfoAndAttrValueDto.getId()));
        log.info("天下游删除接口请求参数={}", JSONObject.toJSONString(params));
        String response = HttpUtil.doGet(salePartner.getOther() + path, params,null);
        if (StringUtils.isEmpty(response)) {
            throw new GlobalException("请求接口失败");
        }
        log.info("天下游删除接口返回参数={}", JSONObject.toJSONString(response));
        Map<String, Object> result = new HashMap<>();
        JSONObject resultJson = JSONObject.parseObject(response);
        if (!"true".equals(resultJson.getString("result"))) {
            result.put("code", 500);
        } else {
            result.put("code", 200);
            ArtRec artRecreq = new ArtRec();
            artRecreq.setConfig(salePartner.getId());
            artRecreq.setAccountId(goodsInfoAndAttrValueDto.getId());
            List<ArtRec> artRecs = artRecMapper.selectArtRecList(artRecreq);
            if(artRecs.size()>0) {
                artRecMapper.deleteArtRecById(artRecs.get(0).getId());
            }
        }
        result.put("req", JSONObject.toJSONString(params));
        result.put("res", response);
        result.put("msg", resultJson.getString("message"));
        return AjaxResult.success(result);
    }


    private JSONArray getLOLR(){
        String r= "{\n" +
                "\t\t\t\"ID\": \"23\",\n" +
                "\t\t\t\"SortName\": \"暗影岛\",\n" +
                "\t\t\t\"ParentID\": \"21\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"ID\": \"24\",\n" +
                "\t\t\t\"SortName\": \"班德尔城\",\n" +
                "\t\t\t\"ParentID\": \"21\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"ID\": \"25\",\n" +
                "\t\t\t\"SortName\": \"裁决之地\",\n" +
                "\t\t\t\"ParentID\": \"21\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"ID\": \"26\",\n" +
                "\t\t\t\"SortName\": \"钢铁烈阳\",\n" +
                "\t\t\t\"ParentID\": \"21\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"ID\": \"27\",\n" +
                "\t\t\t\"SortName\": \"黑色玫瑰\",\n" +
                "\t\t\t\"ParentID\": \"21\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"ID\": \"28\",\n" +
                "\t\t\t\"SortName\": \"巨神峰\",\n" +
                "\t\t\t\"ParentID\": \"21\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"ID\": \"29\",\n" +
                "\t\t\t\"SortName\": \"均衡教派\",\n" +
                "\t\t\t\"ParentID\": \"21\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"ID\": \"30\",\n" +
                "\t\t\t\"SortName\": \"卡拉曼达\",\n" +
                "\t\t\t\"ParentID\": \"21\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"ID\": \"31\",\n" +
                "\t\t\t\"SortName\": \"雷瑟守备\",\n" +
                "\t\t\t\"ParentID\": \"21\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"ID\": \"32\",\n" +
                "\t\t\t\"SortName\": \"诺克萨斯\",\n" +
                "\t\t\t\"ParentID\": \"21\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"ID\": \"33\",\n" +
                "\t\t\t\"SortName\": \"皮城警备\",\n" +
                "\t\t\t\"ParentID\": \"21\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"ID\": \"34\",\n" +
                "\t\t\t\"SortName\": \"皮尔特沃夫\",\n" +
                "\t\t\t\"ParentID\": \"21\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"ID\": \"35\",\n" +
                "\t\t\t\"SortName\": \"守望之海\",\n" +
                "\t\t\t\"ParentID\": \"21\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"ID\": \"36\",\n" +
                "\t\t\t\"SortName\": \"水晶之痕\",\n" +
                "\t\t\t\"ParentID\": \"21\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"ID\": \"37\",\n" +
                "\t\t\t\"SortName\": \"影流\",\n" +
                "\t\t\t\"ParentID\": \"21\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"ID\": \"38\",\n" +
                "\t\t\t\"SortName\": \"战争学院\",\n" +
                "\t\t\t\"ParentID\": \"21\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"ID\": \"39\",\n" +
                "\t\t\t\"SortName\": \"征服之海\",\n" +
                "\t\t\t\"ParentID\": \"21\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"ID\": \"40\",\n" +
                "\t\t\t\"SortName\": \"祖安\",\n" +
                "\t\t\t\"ParentID\": \"21\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"ID\": \"41\",\n" +
                "\t\t\t\"SortName\": \"比尔吉沃特\",\n" +
                "\t\t\t\"ParentID\": \"21\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"ID\": \"42\",\n" +
                "\t\t\t\"SortName\": \"德玛西亚\",\n" +
                "\t\t\t\"ParentID\": \"21\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"ID\": \"43\",\n" +
                "\t\t\t\"SortName\": \"弗雷尔卓德\",\n" +
                "\t\t\t\"ParentID\": \"21\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"ID\": \"44\",\n" +
                "\t\t\t\"SortName\": \"无畏先锋\",\n" +
                "\t\t\t\"ParentID\": \"21\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"ID\": \"45\",\n" +
                "\t\t\t\"SortName\": \"恕瑞玛\",\n" +
                "\t\t\t\"ParentID\": \"21\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"ID\": \"46\",\n" +
                "\t\t\t\"SortName\": \"扭曲丛林\",\n" +
                "\t\t\t\"ParentID\": \"21\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"ID\": \"47\",\n" +
                "\t\t\t\"SortName\": \"巨龙之巢\",\n" +
                "\t\t\t\"ParentID\": \"21\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"ID\": \"48\",\n" +
                "\t\t\t\"SortName\": \"教育网专区\",\n" +
                "\t\t\t\"ParentID\": \"21\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"ID\": \"49\",\n" +
                "\t\t\t\"SortName\": \"男爵领域\",\n" +
                "\t\t\t\"ParentID\": \"21\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"ID\": \"50\",\n" +
                "\t\t\t\"SortName\": \"峡谷之巅\",\n" +
                "\t\t\t\"ParentID\": \"21\"\n" +
                "\t\t},\n" +
                "\t\t{\n" +
                "\t\t\t\"ID\": \"85\",\n" +
                "\t\t\t\"SortName\": \"试练之地\",\n" +
                "\t\t\t\"ParentID\": \"21\"\n" +
                "\t\t},";

        JSONArray objects = JSON.parseArray(r);
        return objects;
    }


    public static void main(String[] args) {

//
//        {
//            "game": "王者荣耀",
//                "price": "1800",
//                "cate_name": "安卓QQ",
//                "p_number": "252309",
//                "imgs":"https://youxihao.oss-cn-zhangjiakou.aliyuncs.com/5f7e912c7f7a7.jpg,https://youxihao.oss-cn-zhangjiakou.aliyuncs.com/5f7e912cb88a8.jpg,https://youxihao.oss-cn-zhangjiakou.aliyuncs.com/5f7e912cec9fc.jpg",
//                "description": "4S 11A 三星长门 三星秽土猿飞日斩 三星金角银角 三星鬼灯幻月 67个秽土波风水门碎片 52个猿飞日斩碎片",
//                "platform": "51youxihao",
//                "title": "WT【安卓抠】50英雄31皮肤安卓Q-50英雄31皮肤-夺萃鹰眼祸源150级，至尊宝，忍炎影，龙腾万里，死亡",
//                "is_indulge": 1,
//                "sign": "DBA10184D15A13385E29BE5DCD461ABC",
//        }
//
//
//        String str = "gm28-安卓q-V7-108英雄-185皮肤-300五级铭文 7王者印记 未来机甲 幽冥火 253幸运值 " +
//                "1内测 蔷薇恋人 零号赤焰 天狼绘梦者 天狼运算者 天狼溯光者 祈雪灵祝 逐梦之星 朱雀志 异界灵契 拒霜思 " +
//                "孙行者 猪悟能 梁祝 地狱火 久胜战神 云霓雀翎 末日机甲女 无限星赏官 原初追逐者 黎明之约 原初探秘者 李小龙 " +
//                "暗隐猎兽者 金属风暴 热力回旋 特工魅影 逐浪之夏 修罗 白龙吟 千年之狐 街头霸王 箭羽风息 星空之诺 鬼剑武藏 " +
//                "朔望之晖 德古拉伯爵 银河之约 暗影游猎 云间偶戏 死神来了 冰冠公主 狂想玩偶喵 单词大作战 花好人间 狰 饕餮 " +
//                "烛龙 重明 穷奇 御霄 御旌 御銮 朔风刀 混沌棋 疑决卦 醍醐杖 万华元夜 女仆咖啡 科学大爆炸 重装意志 奇遇舞章 " +
//                "永昼 营地ID:459926613";
//        String substring = str.substring(0, 150);
//        System.out.println(substring);


        Map<String, Object> params = new TreeMap<>();
//        params.put("game", "王者荣耀");
//        params.put("price", new BigDecimal(1800));
//        params.put("cate_name", "安卓QQ");
//        params.put("p_number", 14356);
//        params.put("imgs", "https://asdasda");
//        params.put("description", "1fasdfadsfasd1");
//        params.put("platform", "yud");
//        params.put("title", "222fdsafasd");


        String cover = MapUntils.getCover(params);
        cover = cover + "key=57bl6a8rs9aosbwfvwq9f736dm1jto6i";
        String sign = DigestUtils.md5Hex(cover).toUpperCase();
        params.put("sign", sign);
//        String response = HttpUtils.sendPost(OutUrlConstant.LCADD, JSONObject.toJSONString(params),"application/json");
        String response = HttpUtils.sendPost("http://www.tianxiajiaoyi.com/api3/game?token=2dc3c4a17507c93557b298852797b4c9", JSONObject.toJSONString(params), "application/json");
        System.out.println(response);
    }


    public static String getSha1(String str) {

        char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
                'a', 'b', 'c', 'd', 'e', 'f' };
        try {
            MessageDigest mdTemp = MessageDigest.getInstance("SHA1");
            mdTemp.update(str.getBytes("UTF-8"));
            byte[] md = mdTemp.digest();
            int j = md.length;
            char buf[] = new char[j * 2];
            int k = 0;
            for (int i = 0; i < j; i++) {
                byte byte0 = md[i];
                buf[k++] = hexDigits[byte0 >>> 4 & 0xf];
                buf[k++] = hexDigits[byte0 & 0xf];
            }
            return new String(buf);
        } catch (Exception e) {
            return null;
        }
    }

    public static String getMD5String(String str) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(str.getBytes("UTF-8"));
            String md5 = new BigInteger(1, md.digest()).toString(16);
            return fillMd5(md5);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    private static String fillMd5(String md5){
        return md5.length() == 32?md5:fillMd5("0"+md5);
    }
}
